#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int s(ll x)
{
    int sum=0;
    while(x)
	{
        sum+=x%10;
        x/=10;
    }
    return sum;
}
int T;
ll n,m,tp[100];
void init()
{
    tp[0]=1;
    for(int i=1;i<=18;i++)
	tp[i]=tp[i-1]*10;
}
void solve()
{
    cin>>n>>m;
    if(s(n)<=m)
	{
        cout<<"0\n";
        return ;
    }
    ll now=n;
    for(int i=0;i<=17;i++)
	{
        if(s(now)<=m)break;
        //cout<<now<<' ';
        ll t=now/tp[i]%10;
        //cout<<t<<' ';
        if(t)now+=(10ll-t)*tp[i];
        //cout<<now<<endl;
    }
    cout<<now-n<<'\n';
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    init();
    cin>>T;
    while(T--)solve();
    return 0;
}
